package com.sw.service.impl;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sw.model.Person;
import com.sw.service.IPersionService;

import net.sf.json.JSONObject;
@Controller
public class PersonServiceImpl implements IPersionService {

	@Override
	public @ResponseBody String hello() {
		
		return "hello来到页面上了";
	}

	@Override
	public @ResponseBody String say(@PathVariable(value="msg") String msg) {
		System.out.println(msg);
		return "{\"msg\":\"you say:'" + msg + "'\"}";
	}

	@Override
	public @ResponseBody String getPerson(@PathVariable(value="id") int id) {
		System.out.println(id+"==XX");
		 Person person = new Person();  
	     person.setName("XXX");  
	     person.setSex("男");  
	     person.setAge(30);  
	     person.setId(id);  
	       
	     JSONObject jsonObject = JSONObject.fromObject(person);  
	     return jsonObject.toString();  
	}

	@Override
	public Object deletePerson(@PathVariable(value="id") int id) {
		System.out.println(id+"==EEEE");
		 JSONObject jsonObject = new JSONObject();  
         jsonObject.put("msg", "成功");  
         return jsonObject;  
	}

	@Override
	public @ResponseBody String addPerson(Person person) {
		 System.out.println("添加id"+person.getId());
		 JSONObject jsonObject = new JSONObject();  
	     jsonObject.put("msg", "成功");  
	     return jsonObject.toString();
	}

	@Override
	public @ResponseBody Object updatePerson(Person person) {
			System.out.println("更新Id"+person.getId());
	        JSONObject jsonObject = new JSONObject();  
	        jsonObject.put("msg", "成功");  
	        return jsonObject.toString();  
	}

}
